﻿using System;
using System.Collections.Generic;
using System.Text;
using MyCode.Data.Models;
using MyCode.IOC;
using MyCode.Tools;
using System.Linq;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.AspNetCore.Http;

namespace MyCode.Application.Impl
{
    public class Sys_UserImpl : ISys_User, ITransientDependency
    {
        public ICacheHelper CacheHelper { get; set; }
        public NFineBaseContext db { get; set; }
        public Tuple<bool, string> SysUserLogin(string userName, string passWord)
        {
          
            var pws = Md5.md5(passWord, 32);
            var name= Md5.md5(userName, 32);
          
            var User = db.SysUserLogOn.Where(m => m.FUserId == name && pws == m.FUserPassword).FirstOrDefault();
            if (User != null)
            {
                CacheHelper.SetCache<SysUserLogOn>(User);
                return new Tuple<bool, string>(true, "");
            }
            else
            {
                return new Tuple<bool, string>(false, "用户名或密码错误!");
            }
        }
    }
}
